package com.items.Tree;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.items.Dao.UnitsMapper;
import com.items.Entity.UnitsBO;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class TreeDemo {

    @Resource
    private UnitsMapper unitsMapper;

    public void test() {
        List<UnitsBO> list = unitsMapper.selectList(
                new LambdaQueryWrapper<>());
        TreeNodeUtil<UnitsBO> treeNodeUtil = new TreeNodeUtil<>(list);
        treeNodeUtil.setRootNodeFunc((bo) -> bo.getParentId() == null);
        treeNodeUtil.setNodeFunc((bo, parent) -> bo.getId().equals(parent.getParentId()));
        List<UnitsBO> tree = treeNodeUtil.buildTree(UnitsBO::setChildren);
        System.out.println(tree);
    }
}